imgPath = 'D:\JC2021\IVUS menkong\test\';        % 图像库路径
imgDir  = dir([imgPath '*.jpg']); % 遍历所有jpg格式文件
SAD = [];
f = zeros(512,512);


for I = 1:length(imgDir)-1          % 遍历结构体就可以一一处理图片了
    image_name = imgDir(I).name;  % 从数组中获取文件名
    f1 = imread([imgPath imgDir(I).name]); %读取每张图片
    f1 = rgb2gray(f1);
    f2 = imread([imgPath imgDir(I+1).name]);%读取后一张图片
    f2 = rgb2gray(f2);
    % 绝对误差和函数SAD
    f = sum(sum(abs(f2-f1)));
    SAD = [SAD;f];
    
    
    
end
    
    
SAD = (SAD - min(SAD))/(max(SAD) - min(SAD));    
% 平均绝对差函数MAD
MAD = SAD/(512*512);

figure(1)
plot(SAD)
% figure(2)
% plot(sum_Fy)
% figure(3)
% plot(sum_Fx+sum_Fy)



% grad_x = gradient(data_x);
% grad_x1 = abs(grad_x);
% grad_y = gradient(data_y);
% grad_y1 = 255 * abs(grad_y);
% grad_xy = grad_x1 + grad_y1;
% plot(grad_xy)